package com.ktjy.thymeleaf.service.impl;

import com.ktjy.thymeleaf.entity.SysUser;
import com.ktjy.thymeleaf.mapper.SysUserMapper;
import com.ktjy.thymeleaf.service.SysUserService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserServiceImpl implements SysUserService {
    @Resource
    private SysUserMapper sysUserMapper;

    @Override
    public SysUser login(String account, String password) {
        SysUser sysUser=sysUserMapper.getUserByAccountWithRoleName(account);
        if (sysUser!=null){
            if (sysUser.getPassword().equals(password)){
                return sysUser;
            }
        }
        return null;
    }

    @Override
    public int addUser(SysUser sysUser) {
        return sysUserMapper.insert(sysUser);
    }

    @Override
    public int deleteUser(Long id) {
        return sysUserMapper.delete(id);
    }

    @Override
    public int updateUser(SysUser sysUser) {
        return sysUserMapper.update(sysUser);
    }

    @Override
    public SysUser getUser(Long id) {
        return sysUserMapper.selectById(id);
    }

    @Override
    public List<SysUser> findAll() {
        return sysUserMapper.getUserListWithRoleName();
    }
}
